package com.it.controller;

import com.it.entity.Hobby;
import com.it.entity.User;
import com.it.exception.CommonException;
import com.it.mapper.*;
import com.it.service.HobbyService;
import com.it.service.LogService;
import com.it.service.UserService;
import com.it.util.ItdragonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class PublicInformationController {
    @Resource
    private HobbyMapper hobbyMapper;
    private static final transient Logger log = LoggerFactory.getLogger(UserController.class);

    @ResponseBody
    @GetMapping(value = "/getPopularHobby.do")
    public List<Hobby> getPopularHobby() {
        List<Hobby> popularHobby = hobbyMapper.getPopularHobby();
        if (popularHobby.size() == 0) {
            throw new CommonException(500, "暂无热门爱好");
        }
        return popularHobby;
    }

    @ResponseBody
    @GetMapping(value = "/getMoreHobbiesUser.do")
    public List<User> getMoreHobbiesUser() {
        List<User> countHobbyForUser = hobbyMapper.getCountHobbyForUser();
        if (countHobbyForUser.size()==0) {
            throw new CommonException(500, "暂无广泛爱好者");
        }
        return countHobbyForUser;
    }


    @ResponseBody
    @GetMapping(value = "/getTheMonthMaxIntegralUser.do")
    public List<User> getTheMonthMaxIntegralUser() {
        List<User> theMonthMaxIntegralUser = hobbyMapper.getTheMonthMaxIntegralUser();
        if (theMonthMaxIntegralUser.size()==0) {
            throw new CommonException(500, "本月无获得积分者");
        }
        return theMonthMaxIntegralUser;
    }
    @ResponseBody
    @GetMapping(value = "/getActiveUser.do")
    public List<User> getActiveUser() {
        List<User> activeUser = hobbyMapper.getActiveUser();
        if (activeUser.size() == 0) {
            throw new CommonException(500, "暂无活跃用户");
        }
        return activeUser;
    }

}
